Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sqlstring

Package Overview
Dependencies
Maintainers
2
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sqlstring

Simple SQL escape and format for MySQL

  • 2.3.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created

What is sqlstring?

The sqlstring npm package is a utility for safely constructing SQL queries by escaping and formatting SQL strings. It helps prevent SQL injection attacks by ensuring that user input is properly escaped before being included in SQL queries.

What are sqlstring's main functionalities?

Escaping Query Values

This feature allows you to safely escape values in SQL queries to prevent SQL injection. The `format` method replaces placeholders in the query with escaped values.

const sqlstring = require('sqlstring');
const userId = 'someUser';
const query = sqlstring.format('SELECT * FROM users WHERE id = ?', [userId]);
console.log(query); // Output: SELECT * FROM users WHERE id = 'someUser'

Escaping Identifiers

This feature allows you to escape SQL identifiers such as table or column names. The `escapeId` method ensures that the identifier is properly quoted.

const sqlstring = require('sqlstring');
const tableName = 'users';
const query = `SELECT * FROM ${sqlstring.escapeId(tableName)}`;
console.log(query); // Output: SELECT * FROM `users`

Escaping Strings

This feature allows you to escape strings to be safely included in SQL queries. The `escape` method adds necessary escape characters to the string.

const sqlstring = require('sqlstring');
const unsafeString = "O'Reilly";
const escapedString = sqlstring.escape(unsafeString);
console.log(escapedString); // Output: 'O\'Reilly'

Escaping and Formatting Objects

This feature allows you to escape and format objects for SQL queries. The `format` method can be used with objects to generate a properly escaped SQL query.

const sqlstring = require('sqlstring');
const user = { id: 1, name: 'John Doe' };
const query = sqlstring.format('INSERT INTO users SET ?', user);
console.log(query); // Output: INSERT INTO users SET `id` = 1, `name` = 'John Doe'

Other packages similar to sqlstring

Keywords

FAQs

Package last updated on 06 Mar 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc